
##################################################
# Predictive validity: Three-Way Interactions (EA) 
##################################################

# specify a list one standard deviation from the standardized mean
#list<- list(neg_id_mean=c(-1,1), pos_id_mean=c(-1,1), InterestedNum=c("0","1")) 
list<- list(neg_id_mean=c(-1.035, 0.739, # uninterested
                          -0.945, 1.215) # interested
            , pos_id_mean=c(-1.355, 0.045, # uninterested
                            -0.25, 1.444), # interested
            InterestedNum=c("0","1")) 
# 1. Activism ==================================================================
# Interaction model
mActivEA<-lm(activism ~ 
             age + education_num + sex_fem  + ideology + # demographics
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = data_EA_cov_std) # data frame with only interested 

# Create interaction data frame
inter_activEA <- emmip(mActivEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, plotit = FALSE) # get a data frame with EMMs
inter_activEA$combination<-paste(inter_activEA$xvar,inter_activEA$tvar, sep = " ") # merge the separate cols containing the conditions/ create combinations
inter_activ_keepEA<-inter_activEA%>% # only keep 
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_activ_keepEA$DV<- "Political activism (H1)"


# 2. News consumption ============================================================
# Interaction model
mNewsEA<-lm(pol_news_con ~ 
            age + education_num + sex_fem  + ideology + # demographics
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = data_EA_cov_std) # data frame with only interested 

# Create interaction data frame
inter_newsEA <- emmip(mNewsEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_newsEA$combination<-paste(inter_newsEA$xvar,inter_newsEA$tvar, sep = " ") # combine conditions
inter_news_keepEA<-inter_newsEA%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_news_keepEA$DV<- "News consumption (H2b)"


# 3. News openness ============================================================
# Interaction model
mOpenEA<-lm(news_openness ~ 
             age + education_num + sex_fem  + ideology + # demographics
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = data_EA_cov_std) # data frame with only interested 

# Interaction data frame
inter_openEA <- emmip(mOpenEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_openEA$combination<-paste(inter_openEA$xvar,inter_openEA$tvar, sep = " ") # combine conditions
inter_open_keepEA<-inter_openEA%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_open_keepEA$DV<- "News openness (H4b; H4d)"

# 4. Political Efficacy ========================================================
# Interaction model
mEffEA<-lm(pol_efficacy ~ 
           age + education_num + sex_fem  + ideology + # demographics
           InterestedNum+
           InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
         data = data_EA_cov_std) # data frame with only interested 

# Create interaction data frame
inter_effEA <- emmip(mEffEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_effEA$combination<-paste(inter_effEA$xvar,inter_effEA$tvar, sep = " ") # combine conditions
inter_eff_keepEA<-inter_effEA%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_eff_keepEA$DV<- "Political efficacy (H2a; H3)"


# 5. Confidence in Knowledge  ==================================================
#Interaction model
mConfEA<-lm(pol_confidence ~ 
            age + education_num + sex_fem  + ideology + # demographics
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = data_EA_cov_std) # data frame with only interested 

# Create interaction data frame
inter_confEA <- emmip(mConfEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_confEA$combination<-paste(inter_confEA$xvar,inter_confEA$tvar, sep = " ") # combine conditions

inter_conf_keepEA<-inter_confEA%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_conf_keepEA$DV<- "Confidence in knowledge (H2c)"

# 6. Political Knowledge  ======================================================
# Interaction model
mKnowEA<-lm(pol_knowledge ~ 
            age + education_num + sex_fem  + ideology + # demographics
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = data_EA_cov_std) # data frame with only interested 

# Create interaction data frame
inter_knowEA <- emmip(mKnowEA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_knowEA$combination<-paste(inter_knowEA$xvar,inter_knowEA$tvar, sep = " ") # combine conditions

inter_know_keepEA<-inter_knowEA%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_know_keepEA$DV<- "Political knowledge (H4a; H4c)"

# Regression table with all six models ----
stargazer(mActivEA, mEffEA, mNewsEA, mOpenEA, mConfEA, mKnowEA,
          type="latex", digits = 2, digits.extra = 0, summary = F, style = "apsr",omit.stat = "f")